package com.alks.function.controller.finance.salary;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.Idempotent;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.UserInfoUtil;
import com.alks.entity.data.entity.PcSalaryDept;
import com.alks.entity.data.entity.PcSalaryRate;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.finance.salary.PcSalaryNewListRequest;
import com.alks.function.data.request.finance.salary.UpdateRemarkRequest;
import com.alks.function.mapper.SdDepartmentMapper;
import com.alks.function.service.finance.salary.PcSalaryDeptService;
import com.alks.function.service.finance.salary.PcSalaryRateService;
import com.alks.function.service.finance.salary.PersonnelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@ApiRestController("/personnel")
@Api(tags = {"工厂-人事薪资作业-人员薪资结算(1+2+3+4)"})
@Slf4j
public class PersonnelController {

    @Resource
    private PersonnelService personnelService;

    @Autowired
    private PcSalaryRateService pcSalaryRateService;

    @Autowired
    private PcSalaryDeptService pcSalaryDeptService;

    @Autowired
    private SdDepartmentMapper sdDepartmentMapper;

    @WebLogger
    @ApiOperation(value = "取数",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/fetchEmployee")
    public ResponseInfo fetchEmployee(@RequestBody Map<String,String> map){
        return personnelService.fetchEmployee(map);
    }

    @WebLogger
    @ApiOperation(value = "资料明细",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/PcSalaryNewList")
    public ResponseInfo PcSalaryNewList(@RequestBody PcSalaryNewListRequest request){
        return personnelService.PcSalaryNewList(request);
    }

    @WebLogger
    @ApiOperation(value = "提成比率建档-查询",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @GetMapping("/PcSalaryRateList")
    public ResponseInfo PcSalaryRateList(){
        return pcSalaryRateService.PcSalaryRateList();
    }

    @WebLogger
    @ApiOperation(value = "提成比率建档-新增",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/addPcSalaryRate")
    public ResponseInfo addPcSalaryRate(@RequestBody PcSalaryRate entity){
        return pcSalaryRateService.addPcSalaryRate(entity);
    }

    @WebLogger
    @ApiOperation(value = "提成比率建档-修改",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PutMapping("/updatePcSalaryRate")
    public ResponseInfo updatePcSalaryRate(@RequestBody PcSalaryRate entity){
        return pcSalaryRateService.updatePcSalaryRate(entity);
    }

    @WebLogger
    @ApiOperation(value = "提成比率建档-删除",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/delPcSalaryRate")
    public ResponseInfo delPcSalaryRate(@RequestParam String id){
        return pcSalaryRateService.delPcSalaryRate(id);
    }

    @WebLogger
    @ApiOperation(value = "管理组别建档-查询",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @GetMapping("/PcSalaryDeptList")
    public ResponseInfo PcSalaryDeptList(){
        return pcSalaryDeptService.PcSalaryDeptList();
    }

    @WebLogger
    @ApiOperation(value = "管理组别建档-修改",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PutMapping("/updatePcSalaryDept")
    public ResponseInfo updatePcSalaryDept(@RequestBody PcSalaryDept entity){
        return pcSalaryDeptService.updatePcSalaryDept(entity);
    }

    @WebLogger
    @ApiOperation(value = "管理组别建档-部门列表",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @GetMapping("/deptList")
    public ResponseInfo deptList(@RequestParam String deptName){
        String companyId = UserInfoUtil.getUserInfo().getCompanyId();
        return ResponseInfo.ok(sdDepartmentMapper.deptList(companyId,deptName));
    }

    @WebLogger
    @ApiOperation(value = "管理组别建档-新增",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PutMapping("/addPcSalaryDept")
    public ResponseInfo addPcSalaryDept(@RequestBody PcSalaryDept entity){
        return pcSalaryDeptService.addPcSalaryDept(entity);
    }

    @WebLogger
    @ApiOperation(value = "管理组别建档-删除",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PutMapping("/delPcSalaryDept")
    public ResponseInfo delPcSalaryDept(@RequestParam String id){
        return pcSalaryDeptService.delPcSalaryDept(id);
    }

    @WebLogger
    @ApiOperation(value = "取月考勤资料",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/RetrieveAttendanceData")
    public ResponseInfo RetrieveAttendanceData(@RequestBody Map<String,String> map){
        return personnelService.RetrieveAttendanceData(map);
    }

    @WebLogger
    @ApiOperation(value = "1 检核月考勤资料/2 取消检核月考勤资料",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/CheckMonthlyAttendance/{choose}")
    public ResponseInfo CheckMonthlyAttendance(@RequestBody Map<String,String> map,@PathVariable("choose") Integer choose){
        return personnelService.CheckMonthlyAttendance(map,choose);
    }

    @WebLogger
    @ApiOperation(value = "1 检核月工资/2 取消检核月工资",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/CheckMonthlySalary/{choose}")
    public ResponseInfo CheckMonthlySalary(@RequestBody Map<String,String> map,@PathVariable("choose") Integer choose){
        return personnelService.CheckMonthlySalary(map,choose);
    }

    @WebLogger
    @ApiOperation(value = "清空资料",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/delPcSalaryNewList")
    public ResponseInfo delPcSalaryNewList(@RequestBody Map<String,String> map){
        return personnelService.delPcSalaryNewList(map);
    }

    @WebLogger
    @ApiOperation(value = "调岗明细",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @GetMapping("/getPcSalaryNewDetailList")
    public ResponseInfo getPcSalaryNewDetailList(@RequestParam String yyyymm,@RequestParam String workerId){
        return personnelService.getPcSalaryNewDetailList(yyyymm,workerId);
    }

    @WebLogger
    @ApiOperation(value = "取计时工资",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/TakeHourlyWages")
    public ResponseInfo TakeHourlyWages(@RequestBody Map<String,String> map){
        return personnelService.TakeHourlyWages(map);
    }

    @WebLogger
    @ApiOperation(value = "取计件工资",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/PieceRateSalary")
    public ResponseInfo PieceRateSalary(@RequestBody Map<String,String> map){
        return personnelService.PieceRateSalary(map);
    }

    @WebLogger
    @ApiOperation(value = "取绩效工资",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/getMeritPay")
    public ResponseInfo getMeritPay(@RequestBody Map<String,String> map){
        return personnelService.getMeritPay(map);
    }

    @WebLogger
    @ApiOperation(value = "计算工资",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/CalculateSalary")
    public ResponseInfo CalculateSalary(@RequestBody Map<String,String> map){
        return personnelService.CalculateSalary(map);
    }

    @WebLogger
    @Idempotent(key = "key.something.{request.workerId}")
    @ApiOperation(value = "修改备注",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/UpdateRemark")
    public ResponseInfo UpdateRemark(@RequestBody UpdateRemarkRequest request){
        return personnelService.UpdateRemark(request);
    }

    @WebLogger
    @ApiOperation(value = "重算工资",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/RecalculateSalary")
    @Idempotent(expireTime = 5,info = "正在重算中,请稍后重试!")
    public ResponseInfo RecalculateSalary(@RequestBody List<UpdateRemarkRequest> request){
        return personnelService.RecalculateSalary(request);
    }

    @WebLogger
    @ApiOperation(value = "导出工资核算表",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/ExportSalaryAccountingTable")
    public void ExportSalaryAccountingTable(@RequestBody PcSalaryNewListRequest request, HttpServletResponse response){
        personnelService.ExportSalaryAccountingTable(request,response);
    }

    @WebLogger
    @ApiOperation(value = "导出工资签核表",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/ExportSalaryApprovalForm")
    public void ExportSalaryApprovalForm(@RequestBody PcSalaryNewListRequest request, HttpServletResponse response){
        personnelService.ExportSalaryApprovalForm(request,response);
    }

    @WebLogger
    @ApiOperation(value = "导出银行确认表",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/ExportSalaryBank")
    public void ExportSalaryBank(@RequestBody PcSalaryNewListRequest request, HttpServletResponse response){
        personnelService.ExportSalaryBank(request,response);
    }

    @WebLogger
    @ApiOperation(value = "导出工资条",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @PostMapping("/ExportPayslip")
    public void ExportPayslip(@RequestBody PcSalaryNewListRequest request, HttpServletResponse response) {
        personnelService.ExportPayslip(request,response);
    }

    @WebLogger
    @ApiOperation(value = "返回默认月份",tags = "工厂-人事薪资作业-人员薪资结算(1+2+3+4)")
    @GetMapping("/getMonth")
    public ResponseInfo getMonth() {
        return personnelService.getMonth();
    }
}